package dao.daoImpl;

import common.DataSourceUtils;
import dao.InfoMapper;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import pojo.User;

import java.sql.SQLException;

/**
 * Created by Administrator on 2017-12-10.
 */
public class InfoMapperImpl implements InfoMapper {

    @Override
    public User selectInfo(Integer id) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql="select * from user where id=?";
        User user=qr.query(sql,new BeanHandler<User>(User.class),id);
        return user;
    }

    @Override
    public int updateInfo(User user) throws SQLException {
        QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
        String sql="update user set password = ?,tl = ? where id=?";
        int result=qr.update(sql,user.getPassword(),user.getTl(),user.getId());
        return result;
    }
}
